/******************************************************************************
 * * ime.h - interface for ime
 *
 * *(C) Copyright 2019 ASR International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#ifndef IME_H_
#define IME_H_

#ifdef __cplusplus
extern "C" {
#endif

/*********************
*      INCLUDES
*********************/
#include "ui_type.h"
#include "ui_textid.h"
#include "lvgl.h"

/*********************
*      DEFINES
*********************/
#define FP_IME_SYM_NUM          28
#define FP_IME_SYM_ELINE_NUM    11
#define FP_IME_CHAR_SHOW_NUM    9

/**********************
*      TYPEDEFS
**********************/

enum
{
    LV_IME_MODE_PINYIN,
    // LV_IME_MODE_STROKE,
    LV_IME_MODE_ENGLISH,
    // LV_IME_MODE_CAPITAL,
    // LV_IME_MODE_LOWER,
    LV_IME_MODE_NUM,
};
typedef UINT8 IME_MODE;    

typedef VOID (*Ime_InputChar_Len)(UINT8 Len);

typedef struct
{
    lv_obj_t          *Ta;
    lv_obj_t          *SymbolLabel;
    IME_MODE          Mode;
    BOOL              Show;
    BOOL              Active;
    BOOL              SingleMode;
    UINT8             Chosen;         /*0: py  1:mb*/
    UINT8             ChosenPyIndex;  /*0-(FP_IME_CHAR_SHOW_NUM-1)*/
    UINT8             ChosenMbIndex;
    UINT8             ChosenEnIndex;
    Ime_InputChar_Len Func;
} Ime_Ext_t;

/*拼音输入法查询码表*/
typedef struct
{
    const char          *T9;
    const char          *PY;
    unsigned short      usSize;
    const unsigned char *MB;
} T9PY_IDX;

/*英文输入查询码表*/
typedef struct
{
    const char *key;
    const char *Letter;
} T9EN_IDX;

typedef struct
{
    unsigned short ausSize[10];
    T9PY_IDX       *pmatchpy[10];
} PY_MATCH_LIST;

/**********************
* GLOBAL PROTOTYPES
**********************/
/**
 * Init Ime
 * param (in) VOID
 * return  VOID
 */
extern VOID Ime_Init(VOID);

/**
 * Is Ime active
 * param (in) VOID
 * return  BOOL
 */
extern BOOL Ime_Is_Active(VOID);

/**
 * Destroy Ime
 * param (in) VOID
 * return  VOID
 */
extern VOID Ime_Destroy(VOID);

/**
 * Set Ime Mode
 * param (in) IME_MODE
 * return  VOID
 */
extern VOID Ime_Set_Mode(IME_MODE Mode);

/**
 * Set Ime Ta
 * param (in) ta pointer to a Text Area object to write there
 * return  VOID
 */
extern VOID Ime_Set_Ta(lv_obj_t *ta);

/**
 * Set Ime Mode Symbol Show/Hide
 * param (in) Show
 * return  VOID
 */
extern VOID Ime_Set_Show(BOOL Show);

/**
 * Set Ime Mode Symbol Pos
 * param (in) x,y
 * return  VOID
 */
extern VOID Ime_Set_SymbolLabel_Pos(UINT16 x, UINT16 y);

/**
 * Get Ime Mode
 * param (in) VOID
 * return IME_MODE
 */
extern IME_MODE Ime_Get_Mode(VOID);
/**
 * Get Ime Ta
 * param (in) VOID
 * return Pointer of Ta
 */
extern lv_obj_t *Ime_Get_Ta(VOID);
/**
 * Get Ime Mode SYMBOL Show
 * param (in) VOID
 * return FALSE/TRUE
 */
extern BOOL Ime_Get_Show(VOID);
/**
 * Ime Key Process
 * param (in) UI_KEY_VALUE
 * return lv_res_t LV_RES_OK--key will return to the window to process
 *                 LV_RES_INV -- key will stop process
 */
extern lv_res_t Ime_Signal(UI_KEY_VALUE Key);

/**
 * Set Get InputChar lenth Func
 * param (in)InPutChar lenth
 * return  VOID
 */
extern VOID Ime_Set_GetCharLen_Func(Ime_InputChar_Len Func);

/**
 * Set Ime SingelMode
 * param (in) TRUE can't set other mode by Ime_Set_Mode
 * return  VOID
 */
extern VOID Ime_Set_SingleMode(BOOL Single);

/**
 * Set Label Parent
 * param (in)Par pointer of parent obj
 * return  VOID
 */
extern VOID Ime_Set_Parent(lv_obj_t *Par);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif  /*IME_H*/
